﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
using FS.Business;
using FS.Common.DotNetBean;
using FS.Common.DotNetCode;
using FS.Common.DotNetUI;

namespace FS.Web.BLL.Visa_Base
{
    public partial class Visa_infoList :PageBase
    {
        private visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PageControl1.pageHandler += new EventHandler(this.pager_PageChanged);
            if (!base.IsPostBack)
            {
                GetSelect_TrustInfo();
                GetSelect_InfoFlag();
                GetSelect_City();
                GetSelect_Operation();
                GetSelect_Certtype();
                GetSelect_Dataintegrity();
            }
        }

        #region 初始项目数据绑定
        //委托方
        private void GetSelect_TrustInfo()
        {
            DataTable dt = _visa.GetSelect_TrustInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_trust, "name", "trust_id", "请选择");
        }       
        
        //签证状态
        private void GetSelect_InfoFlag()
        {
            DataTable dt = _visa.GetSelect_InfoFlag();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_infoflag, "property_value", "property_key", "请选择");
        }

        //所属国家
        private void GetSelect_City()
        {
            DataTable dt = _visa.GetSelect_CityInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_cityid, "city_name", "city_id", "请选择");
        }       
        //经办人
        private void GetSelect_Operation()
        {
            DataTable dt = this._sys_idao.GetSelect_CurrentUserList();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_operation, "user_name", "user_id", "请选择");
        }
        //签证类型
        private void GetSelect_Certtype()
        {
            DataTable dt = _visa.GetSelect_CertType();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_certtype, "property_value", "property_id", "请选择");
        }

        //资料齐全
        public void GetSelect_Dataintegrity()
        {
            DataTable dt = _visa.GetSelect_Dataintegrity();
            ControlBindHelper.BindHtmlSelect(dt, this.sel_fulldata, "property_value", "property_key", "请选择");            
        }
        #endregion

        protected void pager_PageChanged(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
        private void DataBindGrid()
        {
            int count = 0;
            if (this.Hchange.Value == "1")
            {
                this.PageControl1.PageIndex = 1;
                this.Hchange.Value = "0";
            }
            StringBuilder SqlWhere = new StringBuilder();
            IList<SqlParam> IList_param = new List<SqlParam>();
            if (!string.IsNullOrEmpty(this.sel_trust.Value))
            {
                SqlWhere.Append(" and v.trust_id = @trust_id ");
                IList_param.Add(new SqlParam("@trust_id", this.sel_trust.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.info_no.Value))
            {
                SqlWhere.Append(" and v.info_no = @info_no ");
                IList_param.Add(new SqlParam("@info_no", this.info_no.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.sel_certtype.Value))
            {
                SqlWhere.Append(" and d.ref_certtype = @ref_certtype ");
                IList_param.Add(new SqlParam("@ref_certtype", this.sel_certtype.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.info_getdate.Value))
            {
                SqlWhere.Append(" and v.info_getdate = @info_getdate ");
                IList_param.Add(new SqlParam("@info_getdate", this.info_getdate.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.sel_fulldata.Value))
            {
                SqlWhere.Append(" and d.Data_integrity = @Data_integrity ");
                IList_param.Add(new SqlParam("@Data_integrity", this.sel_fulldata.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.sel_cityid.Value))
            {
                SqlWhere.Append(" and d.City_id = @City_id ");
                IList_param.Add(new SqlParam("@City_id", this.sel_cityid.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.cusname.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_user = @InfoDetail_user ");
                IList_param.Add(new SqlParam("@InfoDetail_user", this.cusname.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.info_submitdate.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_Submitdate = @InfoDetail_Submitdate ");
                IList_param.Add(new SqlParam("@InfoDetail_Submitdate", this.info_submitdate.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.cuscard.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_cardno = @InfoDetail_cardno ");
                IList_param.Add(new SqlParam("@InfoDetail_cardno", this.cuscard.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.sel_operation.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_operationid = @InfoDetail_operationid ");
                IList_param.Add(new SqlParam("@InfoDetail_operationid", this.sel_operation.Value.Trim()));
            } 
            if (!string.IsNullOrEmpty(this.cus_phone.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_userphone = @InfoDetail_userphone ");
                IList_param.Add(new SqlParam("@InfoDetail_userphone", this.cus_phone.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.cus_receivedate.Value))
            {
                SqlWhere.Append(" and d.InfoDetail_Receivedate = @InfoDetail_Receivedate ");
                IList_param.Add(new SqlParam("@InfoDetail_Receivedate", this.cus_receivedate.Value.Trim()));
            }
            if (!string.IsNullOrEmpty(this.sel_infoflag.Value))
            {
                SqlWhere.Append(" and d.Ref_infoflag = @Ref_infoflag ");
                IList_param.Add(new SqlParam("@Ref_infoflag", this.sel_infoflag.Value.Trim()));
            }                 

            //只显示当前用户数据
            if (RequestSession.GetSessionUser().isViewAll == "0")
            {
                SqlWhere.Append(" and v.CreateUserId =@userid ");
                IList_param.Add(new SqlParam("@userid", RequestSession.GetSessionUser().UserId.ToString()));
            }

            DataTable dt = this._visa.GetVisaInfoPage(SqlWhere, IList_param, this.PageControl1.PageIndex, this.PageControl1.PageSize, ref count);
            ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
            this.PageControl1.SetPageCount(count);
        }
        
        protected void lbtSearch_Click(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
    }
}